package cn.lystudio.rohm_time_op.controller.webApi;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.util.StrUtil;
import cn.lystudio.rohm_time_op.service.UsmBtRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@SaCheckLogin
@RequestMapping("/webapi/usmBtRecord")
@Slf4j
public class UsmBtRecordController {
    private UsmBtRecordService usmBtRecordService;
    @Autowired
    public void setUsmBtRecordService(UsmBtRecordService usmBtRecordService) {
        this.usmBtRecordService = usmBtRecordService;
    }

    @GetMapping("/getRecord")
    public SaResult getRecord(String selectedMachineNo, String selectedDate) {
        if(StrUtil.isEmpty(selectedDate)) return SaResult.error("日期数据空");
        if(!StrUtil.contains(selectedDate,"~")) return SaResult.error("日期格式异常");
        List<String> selectedDateList = StrUtil.split(selectedDate, "~");

        List<String> topDeptIDList = StpUtil.getPermissionList();
        if((!topDeptIDList.contains("146")) && (!topDeptIDList.contains("1"))) return SaResult.error("无权限");
        return SaResult.data(usmBtRecordService.getList(selectedMachineNo, selectedDateList.get(0).trim(),selectedDateList.get(1).trim()));
    }
}
